package com.线程;

import java.util.concurrent.*;



public class 死锁 {

    static Object obj = new Object();

    static Object obj2 = new Object();

    public static void main(String[] args) throws InterruptedException {

        new Thread(() -> {


            try {
                synchronized (obj) {
                    System.out.println("t1拿到obj锁");

                    Thread.sleep(1000L);
                    synchronized (obj2) {

                        System.out.println("t1拿到obj2锁");
                    }

                }
            } catch (InterruptedException e) {
                e.printStackTrace();
            }


        }
        ).start();


        new Thread(() -> {


            try {
                synchronized (obj2) {
                    System.out.println("t2拿到obj2锁");

                    Thread.sleep(1000L);
                    synchronized (obj) {

                        System.out.println("t1拿到obj锁");
                    }

                }
            } catch (InterruptedException e) {
                e.printStackTrace();
            }


        }
        ).start();

    }


}